<?php
	include("config.php");
	include("cookie.php");
	$username = substr($user, 0, strrpos($user,"|"));

	$pagenum = 10;
	$page = $_GET['page'];
	$query = mysql_query ("select count(*) from friends where username='$username'");
	$res = mysql_fetch_array($query);
	$totalnum = $res[0];
	$totalpage = ceil ($totalnum/$pagenum);
	if (!isset($page))
	{
		$page = 1;
	}
	$startcount = ($page - 1)*$pagenum;
	$sql = "select * from friends where username='$username' limit $startcount,$pagenum";
	$rs=mysql_query($sql);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body><h2>通讯录用户:<?php echo $username;?>已登录<a href="out.php">	退出</a></h2>
<form method="post" action="do-insert.php">
姓名：<input name="name" value=""/>
电话：<input name="phone" value=""/>
ICQ：<input name="icq" value=""/>
地址：<input name="address" value=""/>
<input type="submit" value="添 加" name="submit">
</form>
<br>
<form method="post" action="select.php">
好友：<input name="name" value=""/>
<input type="submit" value="查 询" name="submit"><br/>
<h2>好友列表</h2>
</form>
<?php
$sSQL = "SELECT * FROM friends where username='$username'";
$result = mysql_query($sSQL, $dbLink) or die("数据库Query错误");
$rows = mysql_num_rows($result);
if ($rows > 0)
{
	$i = 1;
	echo "<table border=1>\n";
	echo "<tr><td>NO</td><td>Name</td><td>Telephone</td><td>ICQ</td><td>Address</td><td>操作</td></tr>\n";
	while ($row = mysql_fetch_assoc($rs))
	{
		$name = $row['name'];
		$telephone = $row['telephone'];
		$icq = $row['icq'];
		$address = $row['address'];
		echo "<tr><td>$i</td><td>$name</td><td>$telephone</td><td>$icq</td><td>$address</td><td><a href='edit.php?name=$name&phone=$telephone&icq=$icq&address=$address'>修改</a> <a href='delete.php?name=$name'>删除</a></td></tr>\n";
		++$i;
	}
	echo "</table>\n";
}
else
{
	echo "无结果!<br>";
}
mysql_close ($dbLink);
?>
<table width = "650" broder = "0" align = "center" ceilpadding = "0" ceilspacing = "0">
<tr>
<td aling = "center">
<? if ($page == 1) 
{?>
首页 上页
<?} else {
$prev =($page-1) > 0 ? $page-1 : 1;
?>
<a href = "?page=1">首页</a>
<a href = "?page=<? echo $prev;?>">上页</a>
<?} ?>
<? if ($page < $totalpage) {
$next = $page + 1;?>
<a href = "?page=<? echo $next;?>">下页</a>
<a href = "?page=<? echo $totalpage;?>">末页</a>
<?} else { ?>
下页 末页
<?} ?>
总共<font color = "red"><? echo $totalpage;?></font>页 当前第<font color = "red"><? echo $page;?></font>页 共<? echo $totalnum;?>条记录</td>
</tr>
</table>
</body>
</html>
